<template>
  <el-dialog
    title="提示"
    :visible.sync="dialogVisible"
    width="30%"
    :before-close="handleClose">

    <el-upload
      action="#"
      :auto-upload="false"
      :on-change="handleFileChange"
      :show-file-list="true"
      accept=".xlsx"
    >
      <el-button size="small" type="primary">点击选择文件</el-button>
    </el-upload>

    <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="handleSubmit()" :loading="loading">提交</el-button>
        </span>
  </el-dialog>
</template>
<script>
import {teachingGradesStudentImportApi} from '@/api/teachingIdea/teachingGrades'

export default {
  name: 'TeachingGrades',
  data() {
    return {
      file: '',
      disabled: false,
      loading: false,
      scoreId: '',
      dialogVisible: false,
      selectedFile: '',
    }
  },
  created() {

  },
  methods: {
    handleFileChange(file, fileList) {
      this.selectedFile = file.raw;
    },
    handleSubmit() {
      const form = new FormData();
      form.set('file', this.selectedFile);
      form.set('scoreId', this.scoreId)
      teachingGradesStudentImportApi(form).then(res => {
        if(res.code === 200){
          this.$message.success(res.msg);
          this.$emit('uploadSuccess')
        }
      })
    },
    handleClose() {
      this.dialogVisible = false;
    },
    open(scoreId) {
      this.dialogVisible = true;
      this.scoreId = scoreId;
    }
  }
}
</script>
